home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / Javacup / INGZP26A.TAR / internet / INGZP26A / AboutPopup.java next >
Encoding:
Java Source  |  1996-05-21  |  2.8 KB  |  95 lines

  1. /* $Id: AboutPopup.java,v 1.2 1996/03/31 11:43:02 djun Exp djun $
  2.  
  3.    File: AboutPopup.java
  4.  
  5.    Author: Djun M. Kim
  6.    Copyright (c) 1996 Djun M. Kim.  All rights reserved.
  7.  
  8.    This pops up a frame with an "About this applet" message.
  9. */
  10.  
  11. import java.awt.*;
  12.  
  13. public class AboutPopup extends Frame {
  14.  
  15.     MapInfo parent;
  16.     private DisplayArea message_area;
  17.  
  18.     // Constructor    
  19.     AboutPopup(MapInfo target) {           
  20.     super("About this applet:");
  21.         this.parent = target;            // get our parent
  22.     setBackground(Color.lightGray);
  23.      message_area = new DisplayArea("display_area", this, parent);
  24.     resize(360, 240);
  25.     Point p = parent.location();
  26.     move(p.x + 300, p.y + 100);
  27.     setLayout(new GridLayout(1,1));
  28.     add(message_area);
  29.     }
  30. }
  31.  
  32.  
  33. class DisplayArea extends gridPanel {
  34.  
  35.     final int REMN = GridBagConstraints.REMAINDER;
  36.     Button close;
  37.  
  38.     DisplayArea(String label, Container target, MapInfo parent) {
  39.     super(label, target);
  40.     CenteredText display = new CenteredText();    
  41.     //         Name    gridx    gridy    WeightX    WeightY    gridW    gridH
  42.     make_panel(  display,     1,    1,    1.0,    1.0,    REMN,    1);
  43.     close = 
  44.     make_button("OK",    1,     2,    1.0,    0.0,    REMN,     REMN); 
  45.     }
  46.  
  47.     public boolean action(Event evt, Object arg) {
  48.     if (evt.target instanceof Button) {
  49.         Button b = (Button)evt.target;
  50.         if (b == close) {
  51.         if (getParent().isShowing()) 
  52.            getParent().hide();
  53.         }
  54.     }
  55.     return true;
  56.    }
  57. }
  58.  
  59.  
  60. class CenteredText extends Panel {
  61.  
  62.     private Font bold             = new Font("TimesRoman", Font.BOLD, 18);
  63.     private Font med             = new Font("TimesRoman", Font.PLAIN, 18);
  64.     private Font small             = new Font("TimesRoman", Font.PLAIN, 14);
  65.     private FontMetrics bold_fm     = getFontMetrics(bold);
  66.     private FontMetrics med_fm         = getFontMetrics(med);
  67.     private FontMetrics small_fm     = getFontMetrics(small);
  68.     private String name_string         = "MapInfo demo 1.0";
  69.     private String author_string     = "Copyright (c) 1996  Djun M. Kim";
  70.     private String credits_string     = "Map courtesy of UBC Campus Planning & Development";
  71.     private String info_1         = "Send e-mail to djun@math.ubc.ca for more";
  72.     private String info_2         = "information about this project.";
  73.  
  74.  
  75.     public void drawCentered(String s, Container target, Graphics g, Font f, int voffset) {
  76.     FontMetrics fm     = getFontMetrics(f);
  77.     g.setFont(f);
  78.     int xstart = (target.size().width - fm.stringWidth(s)) / 2;
  79.     int ystart = (target.size().height - fm.getHeight()) / 6;
  80.     g.drawString(s, xstart, ystart + voffset);    
  81.     }
  82.  
  83.     public void paint(Graphics g) {
  84.     setBackground(Color.white);
  85.     setForeground(Color.lightGray);
  86.     drawCentered(name_string, this, g, bold, 10);    
  87.     drawCentered(author_string, this, g, med, 30 );    
  88.     drawCentered(credits_string, this, g, small, 50);    
  89.     drawCentered(info_1, this, g, small, 65);    
  90.     drawCentered(info_2, this, g, small, 80);    
  91.     }
  92. }
  93.  
  94.  
  95.